package com.cskaoyan.shopping.controller;

import com.cskaoyan.mall.commons.result.ResponseData;
import com.cskaoyan.mall.commons.result.ResponseUtil;
import com.cskaoyan.shopping.dto.TestProductDetailDto;
import com.cskaoyan.shopping.service.ITestProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotNull;

@RestController
public class TestProductController {

    @Autowired
    ITestProductService productService;

    @GetMapping("/shopping/test")
    public ResponseData getProductDetail(@NotNull Long productId) {
        TestProductDetailDto productDetail = productService.getProductDetail(productId);
        return new ResponseUtil().setData(productDetail);
    }

    @GetMapping("test/jmeter")
    public String jmeter(HttpServletRequest request) {

        String header = request.getHeader("Content-Type");
        System.out.println("CotentType: " + header);

        Cookie[] cookies = request.getCookies();
        for (Cookie cookie : cookies) {
            if ("access_token".equals(cookie.getName())) {
                System.out.println(cookie.getValue());
                break;
            }
        }

        return "jmeter";
    }
}
